package com.sd.nacosdemo.controller;

import com.sd.nacosdemo.entity.Employee;
import com.sd.nacosdemo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName Employee
 * @Description TODO
 * @date 2021/6/24 14:22
 * @Version 1.0
 */

@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 添加员工信息
     * @param employee
     * @return
     */
    @RequestMapping("/insertEmployee")
    public Object insertEmployee(Employee employee){
        Employee insert = employeeService.insert(employee);
        System.out.println(insert);
        if (insert!=null){
            return "员工信息添加成功！";
        }else {
            return "员工信息添加失败！";
        }
    }

    /**
     * 查询员工信息
     * @param eid
     * @return
     */
    @RequestMapping("/queryEmployee")
    public Object queryEmployee(Long eid){
        Employee employee = employeeService.queryById(eid);
        System.out.println(employee+"   "+eid);
        if (employee!=null){
            return employee;
        }else {
            return "员工信息查询失败！";
        }
    }

    /**
     * 给员工分配导师
     * @param eid
     * @param tid
     * @return
     */
    @RequestMapping("/updateEmployeeAddT")
    public Object updateEmployeeAddT(@Param("eid") Long eid,@Param("tid") Long tid){
        Employee employee = new Employee();
        employee.setEid(eid);
        employee.setTid(tid);
        Employee update = employeeService.update(employee);
        System.out.println(update);
        if (update.getTid()!=null){
            return update;
        }else {
            return "员工导师分配失败！";
        }
    }


}
